import { defineStore } from "pinia";

export const useGlobalStore = defineStore("globalStore", {
    state: () => ({
        // 全局查询参数
        globalSearchForm: {},
    }),
    actions: {
        setGlobalSearchForm(form) {
            const { areaCode, dateType, date, dateTime, beginTime, endTime } = form;
            // 服务端拼接参数
            const params = {
                areaCode,
                dateType,
                ...(dateType === "date" && { date }),
                ...(dateType === "dateTime" && { dateTime }),
                ...(dateType === "dateTimeRange" && { beginTime, endTime }),
            };

            this.globalSearchForm = params;
        },
    },
});
